{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# web数据挖掘 第一周"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 练习1：liepin 工作"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "web mining Engineer\n",
      "{'https://www.liepin.com/job/1917951351.shtml'}\n",
      "SAP ApplicationDevelopment Project Lead\n",
      "{'https://www.liepin.com/job/1926638333.shtml'}\n",
      "计算机化学研究员 Scientist of Computational Chemistry-00174\n",
      "{'https://www.liepin.com/job/1915660198.shtml'}\n",
      "Discovery-Computational Structural Biologist\n",
      "{'https://www.liepin.com/job/1914180892.shtml'}\n",
      "( Senior） Research Manager\n",
      "{'https://www.liepin.com/job/1923198421.shtml'}\n",
      "(Associate）research Director\n",
      "{'https://www.liepin.com/job/1920754473.shtml'}\n",
      "ITA senior AssociateG00065\n",
      "{'https://www.liepin.com/job/1926657791.shtml'}\n",
      "Account Manager 客户经理-大数据平台（快消-零售）\n",
      "{'https://www.liepin.com/job/1923455945.shtml'}\n",
      "NLP 自然语言处理 专家\n",
      "{'https://www.liepin.com/a/18073569.shtml'}\n",
      "Machine Learning Deployment Engineer\n",
      "{'https://www.liepin.com/a/19147549.shtml'}\n",
      "AI软件工程师\n",
      "{'https://www.liepin.com/job/1925171311.shtml'}\n",
      "Data Service Librarian\n",
      "{'https://www.liepin.com/job/1922083517.shtml'}\n",
      "Data Scientist\n",
      "{'https://www.liepin.com/a/19176709.shtml'}\n",
      "Java Leader\n",
      "{'https://www.liepin.com/a/18476197.shtml'}\n",
      "自然语言处理研究员\n",
      "{'https://www.liepin.com/job/198521942.shtml'}\n",
      "Head of Solution, Greater China\n",
      "{'https://www.liepin.com/job/1923087525.shtml'}\n",
      "Platform Architect, TDC\n",
      "{'https://www.liepin.com/job/199260312.shtml'}\n",
      "Senior Manager, Application Architect\n",
      "{'https://www.liepin.com/job/199625698.shtml'}\n",
      "Java Developer(Java开发员)\n",
      "{'https://www.liepin.com/job/198943933.shtml'}\n",
      "Manager, Solution Architect\n",
      "{'https://www.liepin.com/job/198814215.shtml'}\n",
      "Senior Analyst, China Oil Markets 石油能源分析师\n",
      "{'https://www.liepin.com/job/1925812373.shtml'}\n",
      "Shared Service Manager\n",
      "{'https://www.liepin.com/job/1922035413.shtml'}\n",
      "IT Programmer\n",
      "{'https://www.liepin.com/job/199485158.shtml'}\n",
      "Head of Solution\n",
      "{'https://www.liepin.com/a/18296323.shtml'}\n",
      "Machine Learning Deployment Engineer\n",
      "{'https://www.liepin.com/job/1926370455.shtml'}\n",
      "Machine Learning Deployment Engineer\n",
      "{'https://www.liepin.com/job/1926370453.shtml'}\n",
      "Business Analyst\n",
      "{'https://www.liepin.com/job/1925159507.shtml'}\n",
      "Mobile Data Analyst手游数据分析师\n",
      "{'https://www.liepin.com/job/1924886823.shtml'}\n",
      "Ecommerce Data and Insight Manager\n",
      "{'https://www.liepin.com/job/1915662352.shtml'}\n",
      "资深数据分析师 Senior Data Analyst (Mobile)\n",
      "{'https://www.liepin.com/job/1915145798.shtml'}\n",
      "Senior PC Software Engineer/高级PC软件工程师\n",
      "{'https://www.liepin.com/job/1919057165.shtml'}\n",
      "AI Engineer\n",
      "{'https://www.liepin.com/job/1924674841.shtml'}\n",
      "Developer – WeChat, Microsoft LUIS, BotFramework and NLP\n",
      "{'https://www.liepin.com/job/1922703265.shtml'}\n",
      "AI NLP Engineer\n",
      "{'https://www.liepin.com/job/1915650614.shtml'}\n",
      "智能技术开发主管\n",
      "{'https://www.liepin.com/job/1924965947.shtml'}\n",
      "java leader\n",
      "{'https://www.liepin.com/a/18327543.shtml'}\n",
      "Associate Director, Global Risk Management\n",
      "{'https://www.liepin.com/job/1926267845.shtml'}\n",
      "Risk Management Specialist\n",
      "{'https://www.liepin.com/job/1926256361.shtml'}\n",
      "web前端技术经理\n",
      "{'https://www.liepin.com/a/18919987.shtml'}\n",
      "某美资电子科技公司 Machine Learning Deployment Engineer\n",
      "{'https://www.liepin.com/job/1926288075.shtml'}\n"
     ]
    }
   ],
   "source": [
    "from requests_html import HTMLSession #引入模块\n",
    "\n",
    "session = HTMLSession()\n",
    "\n",
    "r = session.get(\"https://www.liepin.com/zhaopin/?key=web+mining\") #网站\n",
    "\n",
    "# 通过xpath找到工作标签\n",
    "news = r.html.xpath('//div[@class=\"job-info\"]/h3/a') #xpath，定位所需内容\n",
    "\n",
    "for new in news:\n",
    "    print(new.text)  # 获得工作标题\n",
    "    print(new.absolute_links)  # 获得工作链接"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. 尝试更换查找的工作"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "市场专员/市场主管 新媒体方向\n",
      "新媒体编辑（金融方向垂直公众号）\n",
      "新媒体销售\n",
      "新媒体文案\n",
      "新媒体编辑（财经新媒体）\n",
      "新媒体网络运营\n",
      "新媒体设计师\n",
      "新媒体商务（直播方向）\n",
      "策划总监（新媒体）\n",
      "新媒体商务（直播方向）\n",
      "新媒体编辑\n",
      "新媒体文案策划主管\n",
      "新媒体推广及平面设计 实习生\n",
      "新媒体营销经理（直播和短视频方向）\n",
      "新媒体品牌运营\n",
      "文案 新媒体文案\n",
      "新媒体\n",
      "新媒体主管\n",
      "新媒体主管\n",
      "新媒体营销\n",
      "新媒体短视频制作\n",
      "新媒体营销\n",
      "新媒体编辑\n",
      "新媒体文案\n",
      "营运督导(具设计&新媒体岗经验)\n",
      "营运督导(具设计&新媒体岗经验)\n",
      "百珏科技-新媒体设计/平面设计/UI设计\n",
      "新媒体编辑\n",
      "新媒体策划\n",
      "新媒体策划（游戏）\n",
      "新媒体发行\n",
      "新媒体推广\n",
      "新媒体（短视频/直播方向）\n",
      "新媒体推广师\n",
      "新媒体（短视频）运营经理\n",
      "运营经理（新媒体）\n",
      "新媒体主管\n",
      "新媒体（品牌文化）\n",
      "新媒体营销经理-1\n",
      "酒店新媒体销售\n"
     ]
    }
   ],
   "source": [
    "from requests_html import HTMLSession #引入模块\n",
    "\n",
    "session = HTMLSession()\n",
    "\n",
    "r = session.get(\"https://www.liepin.com/zhaopin/?key=新媒体\") #key=xxx，更改查找内容\n",
    "\n",
    "# 通过xpath找到工作标签\n",
    "news = r.html.xpath('//div[@class=\"job-info\"]/h3/a') #xpath，定位所需内容\n",
    "\n",
    "for new in news:\n",
    "    print(new.text)  # 获得工作标题"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2. 更改限定城市"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "北京： 市场专员/市场主管 新媒体方向\n",
      "北京： 新媒体编辑（金融方向垂直公众号）\n",
      "北京： 新媒体编辑（财经新媒体）\n",
      "北京： 新媒体推广及平面设计 实习生\n",
      "北京： 新媒体营销经理（直播和短视频方向）\n",
      "北京： 新媒体\n",
      "北京： 新媒体市场专员 — 视频编导方向\n",
      "北京： 新媒体策划\n",
      "北京： 新媒体（短视频/直播方向）\n",
      "北京： 新媒体（短视频）运营经理\n",
      "北京： 运营经理（新媒体）\n",
      "北京： 新媒体策略经理\n",
      "北京： 新媒体活动运营 (MJ003829)\n",
      "北京： 新媒体文案策划\n",
      "北京： 资深新媒体活动策划（丁香医生）（北京）\n",
      "北京： 新媒体营销总监/经理\n",
      "北京： 新媒体营销总监/经理\n",
      "北京： 新媒体营销及运营\n",
      "北京： 实习生（新媒体背景）\n",
      "北京： 汽车新媒体编辑\n",
      "北京： 搜索事业部-新媒体营销负责人\n",
      "北京： 新媒体编辑\n",
      "北京： 新媒体营销总监\n",
      "北京： 新媒体策划经理\n",
      "北京： 新媒体主编\n",
      "北京： 媒介专员（新媒体）\n",
      "北京： 新媒体营销总监/品牌总监\n",
      "北京： 新媒体文案\n",
      "北京： 新媒体与舆情管理岗\n",
      "北京： 平面设计师（新媒体）\n",
      "北京： 新媒体推广高级经理\n",
      "北京： PR经理（新媒体）\n",
      "北京： 新媒体营销高级经理\n",
      "北京： 新媒体英文编辑\n",
      "北京： 新媒体编辑\n",
      "北京： 新媒体文案\n",
      "北京： 财经新媒体编辑\n",
      "北京： 新媒体编辑（大内科方向）\n",
      "北京： 医学项目经理（新媒体方向）\n",
      "北京： 汽车频道新媒体编辑\n",
      "上海： 新媒体架构及运营主管（电商）\n",
      "上海： 新媒体实习生\n",
      "上海： 新媒体网络运营\n",
      "上海： 新媒体设计师\n",
      "上海： 新媒体商务（直播方向）\n",
      "上海： 策划总监（新媒体）\n",
      "上海： 新媒体商务（直播方向）\n",
      "上海： 新媒体主管\n",
      "上海： 新媒体短视频制作\n",
      "上海： 新媒体营销\n",
      "上海： 新媒体策划（游戏）\n",
      "上海： 新媒体发行\n",
      "上海： 电商内容运营/新媒体文案\n",
      "上海： 新媒体推广/营销（小红书、快手、抖音、B站）\n",
      "上海： 景区新媒体营销总监\n",
      "上海： 新媒体 (MJ001182)\n",
      "上海： 新媒体主编\n",
      "上海： 数字营销及新媒体副总监/高级经理\n",
      "上海： 电商新媒体主管\n",
      "上海： 资深新媒体编辑\n",
      "上海： 新媒体文案策划专员 - 云健康\n",
      "上海： 数字营销（新媒体 / 品牌 / 网站）\n",
      "上海： 品牌公关经理/新媒体宣传\n",
      "上海： 新媒体文案\n",
      "上海： 新媒体文案设计\n",
      "上海： 新媒体主管/线上运营主管\n",
      "上海： 点评APP-资深新媒体策划\n",
      "上海： 高级客户主任(新媒体 快消)\n",
      "上海： 新媒体主编（二手奢侈品电商）\n",
      "上海： 新媒体编辑（原创）\n",
      "上海： 新媒体主管\n",
      "上海： 新媒体营销经理（上海）\n",
      "上海： 新媒体编辑（大健康行业）\n",
      "上海： 新媒体推广主管/专员\n",
      "上海： 新媒体编辑\n",
      "上海： 新媒体经理/电商直播\n",
      "上海： 新媒体主管\n",
      "上海： 文案策划（新媒体方向）\n",
      "上海： 新媒体线上销售总监\n",
      "上海： 新媒体销售总监\n"
     ]
    }
   ],
   "source": [
    "from requests_html import HTMLSession #引入模块\n",
    "\n",
    "session = HTMLSession()\n",
    "\n",
    "r = session.get(\"https://www.liepin.com/zhaopin/?key=新媒体&dqs=010\") #dqs=010（北京）\n",
    "r2 = session.get(\"https://www.liepin.com/zhaopin/?key=新媒体&dqs=020\") #dqs=020（上海）\n",
    "# 通过xpath找到工作标签\n",
    "\n",
    "news = r.html.xpath('//div[@class=\"job-info\"]/h3/a') #xpath，定位所需内容\n",
    "news2 = r2.html.xpath('//div[@class=\"job-info\"]/h3/a') #xpath，定位所需内容\n",
    "\n",
    "for new in news:\n",
    "    print(\"北京：\",new.text)  # 获得工作标题\n",
    "for new2 in news2:\n",
    "    print(\"上海：\",new2.text)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3. 抽取城市、薪水等信息"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "城市 北京\n",
      "城市 广州-大石\n",
      "城市 北京\n",
      "城市 深圳\n",
      "城市 北京-望京\n",
      "城市 上海-虹口区\n",
      "城市 上海\n",
      "城市 上海-陆家嘴\n",
      "城市 上海\n",
      "城市 上海\n",
      "城市 上海-虹口区\n",
      "城市 上海\n",
      "城市 广州\n",
      "城市 南京-秦淮区\n",
      "城市 北京\n",
      "城市 北京\n",
      "城市 合肥\n",
      "城市 济南-高新区\n",
      "城市 苏州-常熟\n",
      "城市 上海\n",
      "城市 南京-栖霞区\n",
      "城市 上海\n",
      "城市 上海\n",
      "城市 青岛-崂山区\n",
      "城市 杭州\n",
      "城市 青岛-市南区\n",
      "城市 济南-泺源\n",
      "城市 南京-宁南\n",
      "城市 广州-天河区\n",
      "城市 北京\n",
      "城市 上海\n",
      "城市 上海-浦东新区\n",
      "城市 青岛\n",
      "城市 重庆\n",
      "城市 深圳\n",
      "薪水 10-12k·12薪\n",
      "薪水 面议\n",
      "薪水 面议\n",
      "薪水 7-10k·12薪\n",
      "薪水 面议\n",
      "薪水 8-11k·12薪\n",
      "薪水 2-3k·12薪\n",
      "薪水 8-14k·14薪\n",
      "薪水 6-9k·12薪\n",
      "薪水 面议\n",
      "薪水 20-30k·12薪\n",
      "薪水 面议\n",
      "薪水 8-16k·12薪\n",
      "薪水 8-12k·13薪\n",
      "薪水 2-3k·12薪\n",
      "薪水 6-8k·12薪\n",
      "薪水 面议\n",
      "薪水 6-8k·12薪\n",
      "薪水 15-25k·12薪\n",
      "薪水 6-10k·12薪\n",
      "薪水 12-15k·12薪\n",
      "薪水 5-8k·12薪\n",
      "薪水 7-10k·12薪\n",
      "薪水 8-10k·12薪\n",
      "薪水 5-7k·12薪\n",
      "薪水 8-11k·12薪\n",
      "薪水 7-9k·12薪\n",
      "薪水 7-9k·12薪\n",
      "薪水 8-12k·12薪\n",
      "薪水 面议\n",
      "薪水 5-8k·12薪\n",
      "薪水 面议\n",
      "薪水 6-8k·12薪\n",
      "薪水 6-8k·12薪\n",
      "薪水 5-7k·12薪\n",
      "薪水 面议\n",
      "薪水 5-8k·12薪\n",
      "薪水 10-20k·12薪\n",
      "薪水 8-15k·12薪\n",
      "薪水 10-15k·12薪\n"
     ]
    }
   ],
   "source": [
    "from requests_html import HTMLSession #引入模块\n",
    "\n",
    "session = HTMLSession()\n",
    "\n",
    "r = session.get(\"https://www.liepin.com/zhaopin/?key=新媒体\") #网站\n",
    "\n",
    "# 通过xpath找到工作标签\n",
    "news = r.html.xpath('//div[@class=\"job-info\"]/p/a') #城市\n",
    "news2 = r.html.xpath('//span[@class=\"text-warning\"]') #薪水\n",
    "\n",
    "for new in news:\n",
    "    print (\"城市\",new.text)\n",
    "for new2 in news2:\n",
    "    print (\"薪水\",new2.text)\n",
    "  "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "4. 换个网站试试:自己的jekyll网站"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "产品经理笔记week1\n",
      "学习笔记：决定网页风格的重要一步：背景！\n",
      "学习笔记：markdown里面添加图片不成功？注意一下这几步\n",
      "学习笔记：哭！SVG怎么老是在页面显示不太对？几个方法教你怎么避免这些错误。\n",
      "在网页中使用SVG的方法有哪些？\n"
     ]
    }
   ],
   "source": [
    "from requests_html import HTMLSession #引入模块\n",
    "\n",
    "session = HTMLSession()\n",
    "\n",
    "r = session.get(\"http://tangyuqing.gitee.io/tangyuqing/\") #网站url\n",
    "\n",
    "# 通过xpath找到文章标题标签\n",
    "news = r.html.xpath('//*[@class=\"entry-title\"]/a') #xpath，定位所需内容\n",
    "\n",
    "for new in news:\n",
    "    print(new.text)  # 获得文章标题"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 练习2：图片"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. 图片信息提取"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "from IPython.core.display import display, Markdown"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "全球新冠肺炎病例累计已超15万例\n",
      "杭州西湖龙井茶零星开采\n",
      "伦敦超市现抢购潮\n",
      "成都天府机场复工建设热火朝天\n",
      "昆明餐饮堂食恢复\n",
      "定向降准今起落地\n",
      "美联储降低基础利率至零\n",
      "孙俪\n",
      "罗晋\n",
      "刘诗诗\n",
      "林更新\n",
      "孟子义\n",
      "罗志祥\n",
      "倪妮\n",
      "文艺小学妹\n",
      "治愈系少女\n",
      "洛丽塔少女写真\n",
      "古风少女写真\n",
      "氧气美女\n",
      "清纯芭蕾少女\n",
      "甜系少女写真\n",
      "樱花摄影\n",
      "仙鹤摄影\n",
      "茶园摄影\n",
      "治愈系植物摄影\n",
      "雪山摄影\n",
      "日光摄影\n",
      "水下摄影\n",
      "摩天轮壁纸\n",
      "日历壁纸\n",
      "热气球壁纸\n",
      "非洲大草原壁纸\n",
      "大桥壁纸\n",
      "游戏壁纸\n",
      "小黄人壁纸\n",
      "二次元樱花美景\n",
      "夏目友人帐\n",
      "天使降临到我身边\n",
      "动物狂想曲\n",
      "因为怕痛就全点防御了\n",
      "从零开始的异世界生活\n",
      "某科学的超电磁炮\n"
     ]
    }
   ],
   "source": [
    "from requests_html import HTMLSession\n",
    "\n",
    "session = HTMLSession()\n",
    "\n",
    "r = session.get(\"https://cn.bing.com/images/trending\")\n",
    "\n",
    "# 通过xpath找到工作标签\n",
    "items = r.html.xpath('//div[@class=\"ilp_lf ilp_fl\"]')\n",
    "\n",
    "for url in items:\n",
    "    print(url.text)  # 获得图片文字说明  "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2. 按栏目提取:明星"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'Markdown' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-1-a2cc7d529db8>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m     10\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0murl\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mitems\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     11\u001b[0m   \u001b[1;31m# 获得图片src url\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 12\u001b[1;33m     \u001b[0mdisplay\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mMarkdown\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'![]({url})'\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mformat\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0murl\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0murl\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m: name 'Markdown' is not defined"
     ]
    }
   ],
   "source": [
    "from requests_html import HTMLSession\n",
    "\n",
    "session = HTMLSession()\n",
    "\n",
    "r = session.get(\"https://cn.bing.com/images/trending\")\n",
    "\n",
    "# 通过xpath找到工作标签\n",
    "items = r.html.xpath('//*[@id=\"ilp_t\"]/div[2]/div/div/div/div/a/img/@src')\n",
    "items\n",
    "for url in items:\n",
    "  # 获得图片src url\n",
    "    display(Markdown('![]({url})'.format(url=url)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "按栏目提取:摄影"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/markdown": [
       "![](https://tse1-mm.cn.bing.net/th/id/OET.6570bfa2065f4f2c8074b99429c29e74?w=272&h=272&c=7&rs=1&o=5&pid=1.9)"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/markdown": [
       "![](https://tse1-mm.cn.bing.net/th/id/OET.4ef5bf6f0ae1423abe844d8242f55a80?w=135&h=135&c=7&rs=1&o=5&pid=1.9)"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/markdown": [
       "![](https://tse1-mm.cn.bing.net/th/id/OET.3c15354dfdd047ab93fe96f196ad07cb?w=135&h=135&c=7&rs=1&o=5&pid=1.9)"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/markdown": [
       "![](https://tse1-mm.cn.bing.net/th/id/OET.014e47747fd744729136663e06d30322?w=135&h=135&c=7&rs=1&o=5&pid=1.9)"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/markdown": [
       "![](https://tse1-mm.cn.bing.net/th/id/OET.311ab2c108ce49efb855fed17cae87f8?w=135&h=135&c=7&rs=1&o=5&pid=1.9)"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from requests_html import HTMLSession\n",
    "\n",
    "session = HTMLSession()\n",
    "\n",
    "r = session.get(\"https://cn.bing.com/images/trending\")\n",
    "\n",
    "# 通过xpath找到工作标签\n",
    "items = r.html.xpath('//*[@id=\"ilp_t\"]/div[4]/div/div/div/div/a/img/@src')\n",
    "\n",
    "for url in items:\n",
    "  # 获得图片src url\n",
    "    display(Markdown('![]({url})'.format(url=url)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
